package com.cvpoc.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class FormationInitialeForm extends ActionForm {

	private static final long serialVersionUID = 6970769215269802481L;
	private String dateDebut;
	private String dateFin;
	private String libelle;
	private String id;

	public FormationInitialeForm() {
		super();
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDateDebut() {
		return dateDebut;
	}

	public void setDateDebut(String dateDebut) {
		this.dateDebut = dateDebut;
	}

	public String getDateFin() {
		return dateFin;
	}

	public void setDateFin(String dateFin) {
		this.dateFin = dateFin;
	}

	public String getLibelle() {
		return libelle;
	}

	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}

	public void init() {
		this.setDateDebut(StringUtils.EMPTY);
		this.setLibelle(StringUtils.EMPTY);
		this.setDateFin(StringUtils.EMPTY);

	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		// ActionErrors errors = super.validate(mapping, request);
		System.out.println(mapping.getForward());
		ActionErrors errors = new ActionErrors();
		String parametreMethode = request.getParameter("methode");
		if (StringUtils.isNotBlank(parametreMethode)
				&& (parametreMethode.equals("ajouter") || parametreMethode
						.equals("modifier"))) {

			if (StringUtils.isBlank(getLibelle())) {
				errors.add("formationInitiale.libelle.obligatoire",
						new ActionMessage(
								"formationInitiale.libelle.obligatoire"));
			}
		}
		return errors;
	}
}
